import { Component, OnInit } from "@angular/core";
import { StorageService } from "src/app/core/sotrage/storage.service";
import { Router, ActivatedRoute } from "@angular/router";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { MessageService } from "src/app/core/service/message.service";
import { ApiService } from 'src/app/core/api';
import { DateUtil } from 'src/app/core/util/date-util';

@Component({
    templateUrl: "./myReport.html",
    styleUrls: ["./myReport.scss"]
})
export class MyReportComponent implements OnInit {
    dataList = [];
    tableLoading = false;
    selDate='';
    projectsDatas;
    statusDatas=[
        {v:'',name:'全部'},
        {v:'CREATED',name:'待处理'},
        {v:'PENDING_AUDIT',name:'审核中'},
        {v:'CONFIRMED',name:'已确认'},
        {v:'REPETITIVE',name:'重复'},
        {v:'INVALID',name:'无效'},
    ];
    dateDatas=[]
    page = {
        pages:0,
        pageNo:1,
        status:'',
        belongProject:'',
        beginTime:'',
        endTime:''
    };
    constructor(
        private router: Router, 
        private storageService: StorageService, 
        private message: MessageService, 
        private apiService: ApiService,
        private route: ActivatedRoute,
    ) {}
    getMonthDateList(){
        const array = [];
        const date = new Date();
        const year = date.getFullYear();
        const month = date.getMonth();
        array.push({type:'1',name:'本期数据',beginTime:DateUtil.format(new Date(year,month,1),"yyyy-MM-dd"),endTime:DateUtil.format(new Date(year,month,date.getDate()),"yyyy-MM-dd")});
        for(let i = 1; i<12;i++){
            const beginTime = new Date(year,month-i,1);
            const endTime = new Date(year,month-i+1,0);
            array.push({type:i+1+"",name:beginTime.getFullYear()+"年"+(beginTime.getMonth()+1)+"期",beginTime:DateUtil.format(beginTime,"yyyy-MM-dd"),endTime:DateUtil.format(endTime,"yyyy-MM-dd")});
        }
        console.log(array);
        return array;
    }
    ngOnInit() {
        this.dateDatas = this.getMonthDateList();
        this.dataList = this.route.snapshot.data.userDel.list;
        this.apiService.post('获取白帽项目列表(用于选择框)', {}).then(res => {
            this.projectsDatas = res['data']['list'];
        }).catch(res => {
            res;
        });
    }
    getList(data){
        this.apiService.post('我的漏洞列表', data).then(res => {
			this.dataList = res['data']['list'];
		})
    }

    onChangeDate(date){
        if(date){
            this.page.endTime = date.endTime;
            this.page.beginTime = date.beginTime;
        }else{
            this.page.endTime = '';
            this.page.beginTime = '';

        }
        this.getList(this.page);
    }
    onChangeSearch(){
        this.getList(this.page);
    }

    changeCurrentPage($event){

    }
}
